{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 对活动进行聚类\n",
    "\n",
    "数据来源于Kaggle竞赛：Event Recommendation Engine Challenge，根据\n",
    "events they’ve responded to in the past\n",
    "user demographic information\n",
    "what events they’ve seen and clicked on in our app\n",
    "用户对某个事件是否感兴趣\n",
    "\n",
    "竞赛官网：\n",
    "https://www.kaggle.com/c/event-recommendation-engine-challenge/data\n",
    "\n",
    "活动描述信息在events.csv文件：共110维特征\n",
    "前9列：event_id, user_id, start_time, city, state, zip, country, lat, and lng.\n",
    "event_id：活动的id, \n",
    "user_id：创建活动的用户的id .  \n",
    "city, state, zip, and country： 活动地点 (如果知道的话).\n",
    "lat and lng： floats（活动地点的经度和纬度）\n",
    "start_time： 字符串，ISO-8601 UTC time，表示活动开始时间\n",
    "\n",
    "后101列为词频：count_1, count_2, ..., count_100，count_other\n",
    "count_N：活动描述出现第N个词的次数\n",
    "count_other：除了最常用的100个词之外的其余词出现的次数\n",
    "\n",
    "作业要求：\n",
    "根据活动的关键词（count_1, count_2, ..., count_100，count_other属性）做聚类，可采用KMeans聚类\n",
    "尝试K=10，20，30，..., 100, 并计算各自CH_scores。\n",
    "\n",
    "提示：<font color=#D02090>由于样本数目较多，建议使用MiniBatchKMeans。</font>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "聚类只是调了下模型，从结果上看CH索引和轮廓系数选出的K值差异还是有点大的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 导入工具包\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "from sklearn import metrics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#读取数据\n",
    "import scipy.io as sio\n",
    "eventContMatrix = sio.mmread(\"EV_eventContMatrix\") "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.cluster import MiniBatchKMeans\n",
    "\n",
    "# 一个参数点（聚类数据为K）的模型，并评价聚类算法性能\n",
    "def K_cluster_analysis(K, df):\n",
    "    print(\"K-means begin with clusters: {}\".format(K)); # format(K) 将K变成str类型 https://blog.csdn.net/i_chaoren/article/details/77922939\n",
    "    \n",
    "    #K-means,在训练集上训练\n",
    "    km = MiniBatchKMeans(n_clusters = K)\n",
    "    km.fit(df)\n",
    "    \n",
    "    #保存预测结果\n",
    "    cluster_result = km.predict(df)\n",
    "\n",
    "    # K值的评估标准\n",
    "    #常见的方法有轮廓系数Silhouette Coefficient和Calinski-Harabasz Index\n",
    "    #这两个分数值越大则聚类效果越好\n",
    "    #CH_score = metrics.calinski_harabaz_score(X_train,mb_kmeans.predict(X_train))\n",
    "    \n",
    "    #CH_score = metrics.silhouette_score(df,cluster_result) \n",
    "    #CH_score = metrics.calinski_harabaz_score(df.toarray() ,cluster_result) \n",
    "    CH_score = metrics.calinski_harabaz_score(df.todense() ,cluster_result) \n",
    "    print(\"CH_score: {}\".format(CH_score))\n",
    "\n",
    "    return CH_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "K-means begin with clusters: 10\n",
      "CH_score: 807.0341658396205\n",
      "K-means begin with clusters: 20\n",
      "CH_score: 482.7235183450768\n",
      "K-means begin with clusters: 30\n",
      "CH_score: 362.71936144467145\n",
      "K-means begin with clusters: 40\n",
      "CH_score: 307.8482988567507\n",
      "K-means begin with clusters: 50\n",
      "CH_score: 256.6012055124145\n",
      "K-means begin with clusters: 60\n",
      "CH_score: 230.52236777497072\n",
      "K-means begin with clusters: 70\n",
      "CH_score: 205.29796386743465\n",
      "K-means begin with clusters: 80\n",
      "CH_score: 181.10302046215068\n",
      "K-means begin with clusters: 90\n",
      "CH_score: 170.76377912767242\n",
      "K-means begin with clusters: 100\n",
      "CH_score: 155.4490504462101\n"
     ]
    }
   ],
   "source": [
    "# 设置超参数（聚类数目K）搜索范围\n",
    "CH_scores = []\n",
    "Ks = [10,20,30,40,50,60,70,80,90,100]\n",
    "for K in Ks:\n",
    "    ch = K_cluster_analysis(K, eventContMatrix)\n",
    "    CH_scores.append(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[807.0341658396205, 482.7235183450768, 362.71936144467145, 307.8482988567507, 256.6012055124145, 230.52236777497072, 205.29796386743465, 181.10302046215068, 170.76377912767242, 155.4490504462101]\n"
     ]
    }
   ],
   "source": [
    "print (CH_scores)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x26899ed0a58>]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAHwpJREFUeJzt3X2UlPV5//H3xQKKgCwPCyILLsLWBDURf4uuitUIKCRW8IgwOTYSi8HT5Jea+GxO2l/T1gRb61M1NihpSGIUQQxUiGAJtFEKZleM8qABFGEF3E0EDKIicv3++N5zdhYWdhZm9t655/M6Z87cT7N77ZzhMzfXfOd7m7sjIiLJ1SHuAkREJL8U9CIiCaegFxFJOAW9iEjCKehFRBJOQS8iknAKehGRhFPQi4gknIJeRCThOsZdAECfPn28oqIi7jJERApKbW3tH9y9rKXj2kXQV1RUUFNTE3cZIiIFxczezuY4tW5ERBJOQS8iknAKehGRhFPQi4gknIJeRCThFPQiIgmnoBc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7ZtY/2t8fqI+rvjZ0AXCFmW0GniS0b+4HSs0sffH5cmBbPOW1uTqgzt1XRetzCcFfjK+N0cBb7t7g7p8A84DzKd7XRtrhXgt1wMCM43L23Cjoj4KZGTATWO/u92bsWgBMiZanEHr3iebud7p7ubtXED5o+7W7XwMsAyZGhxXFcwHg7juArWZ2WrRpFLCOInxtEFo21WZ2QvRvJv1cFOVrI8PhXgsLgGuj0TfVwO50i+dY6QtTR8HMRgK/AV6jsS/9HUKf/ilgEOFFfrW7vxdLkTEws4uBW9z9cjM7lXCG3wtYDfylu38cZ31txczOAh4DOgNvAtcRTqqK7rVhZt8DJhNGqq0Grif0nYvitWFmTwAXE2aofBf4f8Avaea1EL0ZPkQYpbMXuM7da3JSh4JeRCTZ1LoREUk4Bb2ISMIp6EVEEk5BLyKScAp6EZGEU9CLiCScgl5EJOEU9CIiCff/Af1q+HVUw5JYAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x26897d8fcc0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 绘制不同聚类数目的模型的性能，找到最佳模型／参数（分数最高）\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "\n",
    "plt.plot(Ks, np.array(CH_scores), 'b-')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "celltoolbar": "Raw Cell Format",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
